import logging

import requests


# 封装公共的操作，例如发送请求操作
class BaseApi:
    sess = requests.session()

    def send(self, **data) -> dict:
        res = self.sess.request(**data)
        if res.status_code != 200:
            logging.debug("请求发生错误")
            return dict()
        else:
            return res.json()

    def get_token(self, corpsecret):
        data = {
            'method': "get",
            'url': 'https://qyapi.weixin.qq.com/cgi-bin/gettoken',
            'params': {
                'corpid': 'wwd47b754539c797c8',
                'corpsecret': corpsecret
            }
        }
        return self.send(**data)['access_token']
